package com.twu.biblioteca;


import java.io.Console;

import java.util.Scanner;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.w3c.dom.Node;
import org.w3c.dom.Element;
import java.io.File;






public class Movies {

    public static int DisplayMovies()
    {
            System.out.println("\n You choosed : 4 \n");
              try {
            System.out.println("The following are the available movies \n");
            System.out.println("================================================= \n");
            File fXmlFile = new File("C:/Users/chethan/twu-biblioteca-sandeshds/movie.xml");
            DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
            Document doc = dBuilder.parse(fXmlFile);
            NodeList nList = doc.getElementsByTagName("movies");
            doc.getDocumentElement().normalize();
            System.out.printf("%-20s %-5s   %-20s %-5s \n ","Movie","Year","Director","Rating");
            for (int temp = 0; temp < nList.getLength(); temp++) {

                Node nNode = nList.item(temp);
                if (nNode.getNodeType() == Node.ELEMENT_NODE) {
                    Element eElement = (Element) nNode;

                    System.out.printf("%-20s %-5s %-20s   %-5s \n ",eElement.getElementsByTagName("movie").item(0).getTextContent(),eElement.getElementsByTagName("year").item(0).getTextContent(),eElement.getElementsByTagName("director").item(0).getTextContent(),eElement.getElementsByTagName("rating").item(0).getTextContent());

                }
            }
            System.out.println("================================================= \n");
        } catch (Exception e) {
            return 0;
        }

            return 1;


    }


}
